package com.ztf.shopping.web.servlet;

import com.ztf.shopping.service.UserService;
import com.ztf.shopping.service.imp.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/sureRegister")
public class SureRegister extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserService userService = new UserServiceImp();
        String userReg = request.getParameter("userReg");
        long seconds = Long.parseLong(request.getParameter("seconds"));
        long now = System.currentTimeMillis();
        if (now-seconds<30*1000){
            userService.sureRegister(userReg);
            response.sendRedirect(request.getContextPath()+"/login.html");
        }



    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
